package com.sg.business.model.dataset.project;

import org.bson.types.ObjectId;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.sg.business.model.Document;
import com.sg.business.model.Folder;
import com.sg.business.model.IModelConstants;
import com.sg.business.model.Project;
import com.sg.widgets.commons.dataset.MasterDetailDataSetFactory;

public class FoldersOfProject extends MasterDetailDataSetFactory {

	public FoldersOfProject() {
		super(IModelConstants.DB, IModelConstants.C_FOLDER);
	}
	
	
	@Override
	public DBObject getQueryCondition() {
		Document doc = (Document) master;
		Project project = doc.getProject();
		ObjectId projectId = project.get_id();
		
		BasicDBObject query = new BasicDBObject();
		query.put(Folder.F_PROJECT_ID, projectId);
		query.put(Folder.F_IS_PROJECT_FOLDERROOT, Boolean.TRUE);
		return query;
	}

//	@Override
//	protected Object getMasterValue() {
//		if (master instanceof Document) {
//			Document doc = (Document) master;
//			Project project = doc.getProject();
//			List<ObjectId> ids = project.getContainersId();
//			
//			
//			return new BasicDBObject().append("$in", ids);
////			
////			Folder parent = null;
////			Folder folder = doc.getFolder();
////			if(!folder.isProjectFolderRoot())
////			{
////			 parent = folder.getParentFolder();
////			}else {
////				return folder.get_id();
////			}
////			while(!parent.isProjectFolderRoot()) {
////				parent = parent.getParentFolder();
////			}
////			return parent.get_id();
//		}
//		return null;
//	}

	@Override
	protected String getDetailCollectionKey() {
		return Folder.F__ID;
	}
}
